//
//  NSMutableArray+Safe.m
//  EPTool
//
//  Created by shiqing guo on 2018/5/9.
//  Copyright © 2018年 云数动能科技. All rights reserved.
//

#import "NSMutableArray+Safe.h"
#import <JRSwizzle.h>
#import <objc/runtime.h>

@implementation NSMutableArray (Safe)

+ (void)load{
    [super load];
    
    NSError* error = nil;
    [objc_getClass("__NSArrayM") jr_swizzleMethod:@selector(objectAtIndex:) withMethod:@selector(safeObjectAtIndex:) error:&error];
    
    [objc_getClass("__NSArrayM") jr_swizzleMethod:@selector(addObject:) withMethod:@selector(safeAddObject:) error:&error];
}

-(id)safeObjectAtIndex:(int)index{
    if(index >= 0 && index < self.count)
    {
        return [self safeObjectAtIndex:index];
    }
    else{
#ifdef DEBUG
        NSAssert(NO,nil);
#endif
    }
    return nil;
}

-(void)safeAddObject:(id)anObject
{
    if(anObject != nil){
        [self safeAddObject:anObject];
    }
}

@end
